package com.blobfish.fiction.common.base.exception;

import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import com.jfinal.kit.PropKit;

import java.io.Serializable;

/**
 * 基础异常类
 */
public abstract class BaseErrorException extends RuntimeException implements Serializable {
    public BaseErrorException() {
    }

    public BaseErrorException(Exception e) {
        super(e);
    }

    public BaseErrorException(Throwable e) {
        super(e);
    }

    public BaseErrorException(String message) {
        super(message);
    }

    public abstract String getId();

    public abstract Object[] getArgs();

    @Override
    public String getMessage() {
        String messageTemplate = PropKit.use("message.txt").get(this.getId());
        if (Validator.isNotEmpty(messageTemplate)) {
            messageTemplate = StrUtil.format(messageTemplate, this.getArgs());
        }
        return messageTemplate;
    }
}
